﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using Hallenberg.SmartClient.Services;
using Hallenberg.SmartClient.Interfaces;
using Microsoft.Practices.Unity;

namespace Hallenberg.SmartClient
{
    public abstract class BaseModule : IBaseModule
    {
        [Dependency]
        public WorkItemController WorkItem { get; set; }

        public void Initialize()
        {
            Debug.Assert(WorkItem != null, "WorkItem != null");

            RegisterServices(this.WorkItem.Services);
            RegisterTranslators(this.WorkItem.Services.Resolve<IEntityTranslatorService>());
            RegisterEvents(this.WorkItem.Events);
        }

        /// <summary>
        /// Register all services exposted by this assembly using the provided service manager.
        /// </summary>
        /// <param name="serviceManager"></param>
        public abstract void RegisterServices(IServiceLocator services);

        /// <summary>
        /// Register all translators using the provided entity translator service.
        /// </summary>
        /// <param name="entityTranslatorService"></param>
        public abstract void RegisterTranslators(IEntityTranslatorService entityTranslatorService);

        /// <summary>
        /// Register all events using the provided EventManager.
        /// </summary>
        /// <param name="events">This event manager instance will be provided by the framework.</param>
        public abstract void RegisterEvents(IEventManager events);
    }
}
